﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NLog;
namespace AirlineCommon
{
    public class AppLogger
    {
        private static Logger logger = LogManager.GetCurrentClassLogger();
        private AppLogger() { }
        public static void Debug(string message, Exception ex, string componentName, string methodName)
        {
            logger.Debug(FormatLogEntry(message, componentName, methodName), ex);
        }
        public static void Info(string message, Exception ex, string componentName, string methodName)
        {
            logger.Info(FormatLogEntry(message, componentName, methodName), ex);
        }
        public static void Warn(string message, Exception ex, string componentName, string methodName)
        {
            logger.Warn(FormatLogEntry(message, componentName, methodName), ex);
        }
        public static void Error(string message, Exception ex, string componentName, string methodName)
        {
            logger.Error(FormatLogEntry(message, componentName, methodName), ex);
        }
        public static void Fatal(string message, Exception ex, string componentName, string methodName)
        {
            logger.Fatal(FormatLogEntry(message, componentName, methodName), ex);
        }
        private static string FormatLogEntry(
                   string message,
                  string componentName, string methodName)
        {
            StringBuilder logEntry = new StringBuilder();

            string sessionId = String.Empty;

            logEntry.Append("<LOGENTRY>");
            logEntry.AppendFormat("<TIMESTAMP>{0}</TIMESTAMP>", DateTime.Now);
            logEntry.AppendFormat("<COMPONENT>{0}</COMPONENT>", componentName);
            logEntry.AppendFormat("<METHOD>{0}</METHOD>", methodName);
            logEntry.AppendFormat("<MSG>{0}</MSG></LOGENTRY>", message);
            logEntry.AppendLine();
            //Them vao event log
            WriteEventLog.WriteLog(logEntry.ToString(),false );
            return logEntry.ToString();
        }
    }
}
